package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.query.StrategyCommentReplyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCommentReplyService;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 攻略点评处理器
 */
@Controller
@RequestMapping("/strategyCommentReply")
public class StrategyCommentReplyController {
    @Autowired
    private IStrategyCommentReplyService strategyCommentReplyService;

    /**
     * 查询待审核状态 / 禁用 / 两者状态的攻略点评
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyCommentReplyQueryObject qo, Model model){
        // 如果没有设置查询状态, 则默认查询已发布的评论
        if (qo.getState() == null){
            qo.setState(1);
        }

        // 根据评论发布时间降序排序
        qo.setOrderBy("scr.createTime desc");

        PageInfo pageInfo = strategyCommentReplyService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "strategyCommentReply/list";
    }

    /**
     * 更改评论发布状态
     * @param id
     * @param state
     * @return
     */
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeReplyState(Long id, Integer state){
        JsonResult result = new JsonResult();
        strategyCommentReplyService.changeReplyState(id, state);
        return result;
    }
}
